import {
	defineStore
} from 'pinia'

import {
	ref
} from 'vue'
export const userStore = defineStore("user", () => {
	let token = ref("")
	let userInfo = ref({})
	let isLogin = ref(false)
	let currentPos = ref({
		longitude:0,
		latitude:0
	})

	function addUserInfo(username,email,phone,token) {
		this.userInfo.name = username
		this.userInfo.email = email
		this.userInfo.phone = phone
		this.token = token
		this.isLogin = true
	}
	// 清除用户登录状态
	function clearUserInfo() {
		this.userInfo = {}
		this.token = ""
		this.isLogin = false
	}

	function setPos(longitude, latitude) {
		currentPos.value.latitude = latitude
		currentPos.value.longitude = longitude
	}

	return {
		token,
		userInfo,
		isLogin,
		addUserInfo,
		clearUserInfo,
		setPos,
		currentPos,
	}
})